var util = require('./util/util.js')

App({
  data: {
    userInfo: null,
  },
  /**
   * 获取用户信息s
   * @return {Promise} 包含获取用户信息的`Promise`
   */
  getUserInfo () {
    return new Promise((resolve, reject) => {
      //if (this.data.userInfo) return reject(this.data.userInfo);
      util.login()
          .then(res => {
            return util.getUserInfo()
          })
          .then(res => {
            console.log(res.userInfo)
            return res.userInfo
          })
          .then(info => (this.data.userInfo = info))
          .then(info => resolve(info))
          .catch(error => console.error('failed to get user info, error: ' + error))
    })
  },
  onLaunch: function () {
    console.log('App Launch')
  },
  onShow: function () {
    console.log('App Show')
  },
  onHide: function () {
    console.log('App Hide')
  },
  globalData: {
    hasLogin: false
  }
})
